#include<stdio.h>
#include<malloc.h>
#include<math.h>

int getdis(int x,int y,int m,int n,unsigned char* s){
int tmp = 0;
int dis = 0;
int a,b;
if(*(s+x*(n+1)+y)=='1'){
return 0;
}else{
for(a=0;a<m;++a){
for(b=0;b<n;++b){
tmp = 0;
if(a==x&&b==y){
continue;
}else{
if(*(s+a*(n+1)+b)=='1'){
tmp = abs(a-x) + abs(b-y);
if(dis == 0||dis > tmp){
dis=tmp;
}
}
}
}
}
}
return dis;
}

int main(){
int m,n,i,q,tmp;
unsigned char* s;
int* r;
scanf("%d %d",&m,&n);
s = (unsigned char*)malloc(sizeof(unsigned char)*m*(n+1));
r = (int*)malloc(sizeof(int)*m*n);
for(i=0;i<m*(n);++i){s[i]=0;r[i]=0;}
for(i=m*(n);i<m*(n+1);++i){s[i]=0;}
for(i=0;i<m;++i){
scanf("%s",s+i*(n+1));
}
for(i=0;i<m;++i){
for(q=0;q<n;++q){
*(r+i*n+q) = getdis(i,q,m,n,s);
}
}
for(i=0;i<m;++i){
for(q=0;q<n;++q){
printf("%d ",*(r+i*n+q));
}
printf("\n");
}
free(s);
free(r);
return 0;
}